package com.by.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wang
 * @version 版本号 ${}
 * @className WebMvcConfig
 * @日期 2024/9/6 16:14
 * @since jdk1.8
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    
    /**
     * 处理跨域请求CORS
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //  “/**” 拦截所有请求
                .allowCredentials(false) //不允许携带cooking
                .allowedHeaders("*") //允许所有的请求头
                .allowedOrigins("*") //允许来自所有的域名访问
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS") //允许那些方法跨域
                .maxAge(3600); //预检缓存时间
    }
}
